{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "hi_train.ipynb",
      "version": "0.3.2",
      "provenance": [],
      "collapsed_sections": [],
      "toc_visible": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "accelerator": "GPU"
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "XeA0d4hJxfC_",
        "colab_type": "text"
      },
      "source": [
        "**注意**\n",
        "\n",
        "每次使用前点击菜单栏的runtime选项的Reset all runtimes，初始化Colab环境\n",
        "\n",
        "在修改-笔记本设置选项中选择GPU\n",
        "\n",
        "请勿在Google Drive的目录里运行代码\n",
        "\n",
        "Colab断开连接后，短时间重连不会中断\n",
        "\n",
        "频繁切换工作目录是为了方便使用cp复制命令，因为My Drive文件夹名字中有空格，My Drive不能出现在cp命令中"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "oPXCf2pzrbbz",
        "colab_type": "text"
      },
      "source": [
        "# 1. Import Google Drive\n",
        "\n",
        "创建工作文件夹\n",
        "\n",
        "挂载Google Drive\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "0LOeyvQgK4-d",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "mkdir ./sample_data/mydata"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "4a2a089K4sOw",
        "colab_type": "code",
        "outputId": "2f095475-4f19-430c-d24e-37c00918e8dc",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 125
        }
      },
      "source": [
        "from google.colab import drive\n",
        "drive.mount('/content/drive')"
      ],
      "execution_count": 2,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Go to this URL in a browser: https://accounts.google.com/o/oauth2/auth?client_id=947318989803-6bn6qk8qdgf4n4g3pfee6491hc0brc4i.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=email%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdocs.test%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.photos.readonly%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fpeopleapi.readonly&response_type=code\n",
            "\n",
            "Enter your authorization code:\n",
            "··········\n",
            "Mounted at /content/drive\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Q1geW20arsK5",
        "colab_type": "text"
      },
      "source": [
        "# 2. Enter the Google Drive\n",
        "\n",
        "将文件从Google Drive复制到Colab"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "kaN-o7fyX6ys",
        "colab_type": "code",
        "outputId": "6eb5c6b0-a553-4763-b1cd-ff1d57aa5548",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "cd /content/drive/My Drive"
      ],
      "execution_count": 3,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "/content/drive/My Drive\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "CI-JbqA3M9Ec",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "!cp ./HWDB/mtrn.zip /content/sample_data/mydata/trn.zip\n",
        "!cp ./HWDB/mval.zip /content/sample_data/mydata/val.zip\n",
        "!cp ./HWDB/dtst.zip /content/sample_data/mydata/tst.zip"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "6rMHHpCMvO4U",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "!cp ./hi_codes/train.py /content/sample_data/mydata/train.py"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "vvQDoPvfsi02",
        "colab_type": "text"
      },
      "source": [
        "# 3. Enter the Colab\n",
        "\n",
        "解压压缩包并统计解压后文件数量"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vG8-LcvWX28u",
        "colab_type": "code",
        "outputId": "faeed26f-9dd6-4e97-ff20-d1eb57461e53",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "cd /content/sample_data/mydata"
      ],
      "execution_count": 6,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "/content/sample_data/mydata\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "R2BNzB5fLRqI",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 70
        },
        "outputId": "16dba8dc-039c-445e-b5dc-08f1f777618e"
      },
      "source": [
        "!unzip -q trn.zip\n",
        "!ls -lR trn*/|grep \"^-\"| wc -l\n",
        "!unzip -q val.zip\n",
        "!ls -lR val*/|grep \"^-\"| wc -l\n",
        "!unzip -q tst.zip\n",
        "!ls -lR tst*/|grep \"^-\"| wc -l"
      ],
      "execution_count": 7,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "897202\n",
            "112265\n",
            "107808\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "2DXeElpwtPX3",
        "colab_type": "text"
      },
      "source": [
        "# 4. Run the program\n",
        "\n",
        "运行程序"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "HFA85Ejx-NJO",
        "colab_type": "code",
        "outputId": "26d8e880-5dec-4ebe-a4e7-ac38bc0d8611",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "cd /content/sample_data/mydata"
      ],
      "execution_count": 8,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "/content/sample_data/mydata\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "fU-AL6VgXqNi",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "!python train.py"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "IZllNDoWPG6a",
        "colab_type": "text"
      },
      "source": [
        "# 5. Save files\n",
        "保存文件"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "RPReyBSJPNnD",
        "colab_type": "code",
        "outputId": "16ebd1f2-7aaa-4a12-c078-0d7a7efbc2a3",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "cd /content/drive/My Drive"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "/content/drive/My Drive\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "XgZNij4gXzH6",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "cp /content/sample_data/mydata/model1.h5 ./hi_results/model1.h5"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "UIWZtFi0VrdL",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "cp /content/sample_data/mydata/log1.csv ./hi_results/log1.csv"
      ],
      "execution_count": 0,
      "outputs": []
    }
  ]
}
